﻿
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <title>选择客户</title>
    <link rel="stylesheet" type="text/css" href="../plugins/weui/css/weui.min.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css">
    <link rel="stylesheet" type="text/css" href="../css/css.css">
    <style media="screen">
        body{background-color:#F3F3F3}
.container{margin-bottom:100px}
.weui-cells{margin-top:0}
.header{background-color:#F0EEF4;color:#7F7E83;font-size:14px}
.selectimg{width:30px}
.selectimg img{width:20px;height:20px;border-radius:50%}
.sure_btn{width:100%;padding:15px 0;background-color:#fff;position:fixed;bottom:0}
.save_btn {
    border-radius: 5px;
    color: #fff;
    margin-top: 25px;
    margin-bottom: 25px;
    width: 80%;
    margin-left: auto;
    margin-right: auto;
    background-color: #FE7B03;
    border: none;
}
</style>
</head>

<body>
    <div class="container">
        <div class="weui-cells header">
            <div class="weui-cell ">
                <div class="weui-cell__bd">
                    <p>客户列表</p>
                </div>
            </div>
        </div>
        <div id="mescroll" class="mescroll">
            <div class="weui-cells wess client-list">
            </div>
        </div>





        <div class="sure_btn">
   
            <div class="button-sp-area save_btn">
                <a href="javascript:;" class="weui-btn btn-submit">添 加</a>
            </div>
        </div>
    </div>
<script type="text/javascript" src="../js/jquery-2.1.4.min.js"></script>
<script src="../plugins/dropload/js/mescroll.min.js"></script>
<script type="text/javascript" src="../js/base.js"></script>
<script type="text/javascript">
    var mescroll = null;
    $(function () {
        mescroll = getPager(loadClient);  //分页
   
        $('body').on('click','.choose',function () {
            var clientId = $(this).attr('attrid');
            var src = $('.img' + clientId).attr("src");
            if(src == '../images/boss/select.png'){
                $('.img' + clientId).attr("src","../images/boss/selected.png")
            }else {
                $('.img' + clientId).attr("src","../images/boss/select.png")
            }
        })
    });

    //未添加标签的客户
    function loadClient(pageObj) {
        var tagId = getQueryString("clientTagid");
        ajaxGet(siteApiList.GetClientListByTag + "?staffId=1&tagid=" + tagId + "&page=" + pageObj.num, function (data) {

            
            if(isNoData(data.Data.List)){
                $(".client-list").append(getNoDataMsg(pageObj.num));
                mescroll.endSuccess(0);  //设置条数
                return;
            }
            mescroll.endSuccess(data.Data.List.length);  //设置条数
            var list = data.Data.List;
            var html = "";
            for (var i = 0; i < list.length; i++) {
                var item = list[i];
                html += "<div class='weui-cell weui-cell_access choose' attrid='" + item.Id + "'>"
                html += "<div class='selectimg'>"
                html += "<img class='img" + item.Id + "' id='img" + i + "' data-clientid='" + item.Id + "' src='../images/boss/select.png'/>"
                html += "</div>"
                html += "<div class='weui-cell__hd'>"
                html += "<img src=" + siteConfig.formatAvater(item.Avater) + " style='width:32px;height: 32px;margin-right:10px;display:block;'>"
                html += "</div>"
                html += "<div class=weui-cell__bd weui-Detail><p>" + item.NickName + "</p>"
                html += "</div></div>"
            }
            $(".client-list").append(html);
            bindBtn();
        });
    }

    function bindBtn() {
        //确认提交
        $(".sure_btn").on("click", function () {
            var clientId = "";
            var clientTagid = getQueryString("clientTagid");
            $(".choose").each(function (index, item) {
                var src = $('#img' + index).attr("src");
                if (src == "../images/boss/selected.png") {
                    clientId += $(item).attr('attrid') + ',';
                }
            })
            clientId = clientId.substring(0, clientId.length - 1);
            ajaxPost(siteApiList.AddClientTagRelations, "staffId=1&clientTagId=" + clientTagid + "&clientIds=" + clientId, function (res) {
                if (!isJsonSuccess(res))
                    return;
                window.location.href = "newLabel.html?Id=" + clientTagid;
            });
        })
    }
      



</script>



</body>

</html>
